import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;

enum RomanNumeralEnum {
    I, V, X, L, C, D, M
}

class RomanNumeral {

    private final static int I = 1;
//    private final static int V = 5;
    private final static int X = 10;
//    private final static int L = 50;
    private final static int C = 100;
//    private final static int D = 500;
    private final static int M = 1000;

    private int i;
    private int x;
    private int c;
    private int m;

    {
        this.i = 0;
        this.x = 0;
        this.c = 0;
        this.m = 0;
    }

    RomanNumeral(int inputNumber) {
        int tmp;
        this.m = inputNumber / RomanNumeral.M;
        tmp = inputNumber % RomanNumeral.M;
        this.c = tmp / RomanNumeral.C;
        tmp = tmp % RomanNumeral.C;
        this.x = tmp / RomanNumeral.X;
        tmp = tmp % RomanNumeral.X;
        this.i = tmp / RomanNumeral.I;
    }

    String getRomanNumeral() {
        StringBuilder result = new StringBuilder();

        result.append(this.getRomanNumeral(this.m, RomanNumeralEnum.M));
        result.append(this.getRomanNumeral(this.c, RomanNumeralEnum.C));
        result.append(this.getRomanNumeral(this.x, RomanNumeralEnum.X));
        result.append(this.getRomanNumeral(this.i, RomanNumeralEnum.I));

        return result.toString();
    }


    private String getRomanNumeral(int number, RomanNumeralEnum r) {
        StringBuilder sb = new StringBuilder();

        if (number >= 4 && number <= 8) {
            if (number > 5) {
                int tmp = number % 5;
                switch (r) {
                    case I:
                        IntStream.range(0, tmp).forEach((i) -> sb.append("I"));
                        return "V" + sb.toString();
                    case X:
                        IntStream.range(0, tmp).forEach((i) -> sb.append("X"));
                        return "L" + sb.toString();
                    case C:
                        IntStream.range(0, tmp).forEach((i) -> sb.append("C"));
                        return "D" + sb.toString();
                    case M:
                    case V:
                    case L:
                    case D:
                    default:
                        return "";
                }
            }
            if (number < 5) {
                switch (r) {
                    case I:
                        return "IV";
                    case X:
                        return "XL";
                    case C:
                        return "CD";
                    case M:
                    case V:
                    case L:
                    case D:
                    default:
                        return "";
                }
            }
//            number == 5
            switch (r) {
                case I:
                    return "V";
                case X:
                    return "L";
                case C:
                    return "D";
                case M:
                case V:
                case L:
                case D:
                default:
                    return "";
            }
        }

        if (number == 9) {
            switch (r) {
                case I:
                    return "IX";
                case X:
                    return "XC";
                case C:
                    return "CM";
                case M:
                case V:
                case L:
                case D:
                default:
                    return "";
            }
        }

        if (number < 4) {
            int tmp = number % 4;

            switch (r) {
                case I:
                    IntStream.range(0, tmp).forEach((i) -> sb.append("I"));
                    return sb.toString();
                case X:
                    IntStream.range(0, tmp).forEach((i) -> sb.append("X"));
                    return sb.toString();
                case C:
                    IntStream.range(0, tmp).forEach((i) -> sb.append("C"));
                    return sb.toString();
                case M:
                    IntStream.range(0, tmp).forEach((i) -> sb.append("M"));
                    return sb.toString();
                case V:
                case L:
                case D:
                default:
                    return "";
            }
        }

        return "";
    }
}